package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements Operation {
    @Override
    public void work(BookList bookList) {
        System.out.println("下架一本书!");

        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入要下架的图书名称：");
        String name = scanner.nextLine();
        int index = bookList.getBookIndexByName(name);
        if (index != -1) {
            int bookListSize = bookList.getBookListSize();
            for (int i = index; i < bookListSize - 1; i++) {
                bookList.setBookByPos(bookList.getBookByPos(i + 1), i);
            }
            bookList.setBookByPos(null, bookListSize - 1);
            bookList.setBookListSize(bookListSize - 1);

            System.out.println("下架成功成功!");
        } else {
            System.out.println("没有查找到 " + name);
        }
    }
}
